<template>
  <div class="recommended">
    <div class="title tanxin">
      <div class="title_l tanxin">
        <img src="../../assets/images/quan.png" alt="" />
        <h2>热门推荐</h2>
        <ul class="tanxin">
          <li v-for="(item, index) in catList" :key="index" @click="$router.push(`/discover/songmenu?cat=${item}`)">{{ item }}</li>
        </ul>
      </div>
      <div class="more">
        <span @click="$router.push(`/discover/songmenu`)">更多</span>
        <img src="../../assets/images/jiantou.png" alt="" />
      </div>
    </div>

    <div class="content">
      <ul class="tanxin">
        <li v-for="(item, index) in Hotsong" :key="index">
          <div class="info" @click="$router.push(`/playlist/${item.id}`)">
            <img :src="item.picUrl" alt="" />
            <i :title="item.name" class="cover"></i>
            <i :class="{'vip':item.highQuality}" ></i>
            <div class="listen tanxin">
              <span>
                <i class="headset"></i>
                {{ item.playCount }}万
              </span>
              <i title="播放" class="play"></i>
            </div>
          </div>
          <!-- 文字超过第2行显示... -->
          <p :title="item.name" class="clamp" @click="$router.push(`/playlist/${item.id}`)">{{ item.name }}</p>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { HotApi } from "@/request/api";
export default {
  data() {
    return {
      Hotsong: "",
      catList: ["华语","流行","摇滚","民谣","电子"],
    };
  },
  created() {
    HotApi().then((res) => {
      // console.log(res);
      this.Hotsong = res.data.result;
    });
  },
};
</script>
 
<style lang = "less" scoped>
@import "../../assets/base.less";
.recommended {
  .title {
    height: 35px;
    border-bottom: 2px solid @red;
    margin: 20px 0;
    display: flex;
    align-items: center;
    .title_l {
      img {
        width: 15px;
        height: 15px;
        margin: auto;
        padding: 0 10px;
      }
      h2 {
        font-size: 20px;
      }
      ul {
        display: flex;
        align-items: center;
        li {
          cursor: pointer;
          font-size: 12px;
          color: #666666;
          border-right: 1px solid #666666;
          padding: 0 15px;
          &:last-of-type {
            border: none;
          }
          &:hover {
              text-decoration: underline;
              color: #666;
          }
        }
      }
    }
    .more {
      span {
        cursor: pointer;
        font-size: 12px;
        color: #666666;
        &:hover {
          text-decoration: underline;
        }
      }
      img {
        margin: auto;
        padding: 0 5px;
      }
    }
  }
  .content {
    ul {
      flex-wrap: wrap;
      display: flex;
      justify-content: flex-start !important;
      li {
        height: 200px;
        width: 138px;
        margin-bottom: 30px;
        margin-right: 52px;
        &:nth-of-type(4n) {
          margin-right: 0;
        }
        .info {
          cursor: pointer;
          position: relative;
          width: 140px;
          height: 140px;
          overflow: hidden;
          img {
            width: 140px;
            height: 140px;
          }
          &:hover {
            img {
              transform: scale(1.2);
            }
          }
          .cover {
            position: absolute;
            top: 0;
            left: 0;
            height: 140px;
            width: 140px;
            background: url("@/assets/images/public/coverall.png")no-repeat -0px -0px;
          }
          .vip {
            position: absolute;
            top: 0;
            left: 0;
            width: 40px;
            height: 40px;
            display: block;
            background: url("@/assets/images/public/icon2.png") no-repeat -135px -220px;
          }
          .listen {
            width: 100%;
            height: 27px;
            background-color: rgba(0, 0, 0, 0.5);
            position: absolute;
            bottom: 0;
            left: 0;
            span {
              color: #ccc;
              font-size: 12px;
              line-height: 27px;
              text-align: center;
            }
            .headset {
              float: left;
              width: 17px;
              height: 17px;
              margin: 2px 5px;
              background: url("../../assets/images/public/iconall.png") no-repeat -0px -18px;
            }
            .play {
              float: left;
              width: 17px;
              height: 17px;
              margin: 4px 8px;
              background: url("../../assets/images/public/iconall.png") no-repeat -0px -0px;
              &:hover {
                  background-position: 0 -60px;
                  cursor: pointer;
              }
            }
          }
        }
        .clamp {
          font-size: 14px;
          color: #000;
          line-height: 1.4;
          margin-top: 8px;
          display: list-item;
          text-align: -webkit-match-parent;
          overflow:hidden; 
          text-overflow:ellipsis; 
          display:-webkit-box; 
          -webkit-box-orient:vertical; 
          -webkit-line-clamp:3;
          &:hover {
            cursor: pointer;
            text-decoration: underline;
          }
        }
      }
    }
  }
}
</style>